install_mariadb__info_set(){
    #设置与检测数据库root密码配置
    root=`openssl rand -base64 8|md5sum|cut -c 1-8 `
    input "请输入密码[ root ],默认[ ${root} ]:" root_pass
    input_check "$root_pass" "数据库[root]密码" "$root" "root_pass"

    #数据库初始权限配置
    input "是否关闭[ root ]用户远程登录[ y/n ],默认[ y ]" dislogin
    input_check "$dislogin" "数据库[ root ]用户登录权限" "y" "dislogin"

    #是否删除测试数据库
    input "是否删除[ test ]数据库[ y/n ],默认[ y ]" rm_db
    input_check "$rm_db" "删除[ test ]数据库确认" "y" "rm_db"

    #结果汇总
    red_z_green_z "数据库[ root ]用户密码:" "[ $root_pass ]"
    red_z_green_z "允许[  root  ]远程登录:" "[ $dislogin ]"
    red_z_green_z "是否删除[ test ]数据库:" "[ $rm_db ]"
    input "是否继续[回车继续]" Y
}
install_mariadb__install(){
    service_install "mariadb-server"
}
install_mariadb__sql_cmd(){
    mysql_cmd="mysql -uroot -p${root_pass} -e "
    $mysql_cmd "$1"
    chek_status "$?" "数据库命令执行: [ $1 ]"
}
install_mariadb__init(){
    if [[ -n "$1" ]];then
        root_pass=$1
    fi
    service_start "mariadb"
    mysql -e "show databases;"
    #设置密码
    mysql -e "use mysql;UPDATE mysql.user SET authentication_string = PASSWORD('${root_pass}'), plugin = 'mysql_native_password' WHERE User = 'root';"
    service_start 'mariadb'
    #设置远程登录权限
    if [[ "$dislogin" -eq 'n' ]];then
        install_mariadb__sql_cmd "grant all privileges on *.* to 'root'@'%' identified by '${root_pass}';"
    else
        install_mariadb__sql_cmd "grant all privileges on *.* to 'root'@'localhost' identified by '${root_pass}';"
    fi
    #删除测试数据库
    check_test=`$mysql_cmd "show databases;"`

    if [[ -n `echo $check_test | grep test` ]];then
        install_mariadb__sql_cmd "drop database test;"
    fi
    install_mariadb__sql_cmd "flush privileges;"
    install_mariadb__sql_cmd "show databases;"
    chek_status "$?" "数据库安装与设置初始密码"
    green_zt "数据库[ mariadb ]安装配置完成,安装信息如下:"
    red_z_green_z "数据库[ root ]用户密码:" "[ $root_pass ]"
}